package cn.com.dstz.utils;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import cn.com.dstz.admin.constants.Constants;


public class ActionUtils{
	
	/**
	 * @param admin
	 * @param key
	 * @return
	 * @deprecated
	 */
	@Deprecated
	public static Byte getConfigValue( Map< String, Object > admin, String key ){
		// 返回只允许查看自己的
		if( !hasConfig( admin )){
			return 0;
		}
		
		return ( Byte ) ( getConfig( admin ).get( key ) );
	}
	/**
	 * 获取附加权限
	 * @param admin
	 * @return
	 * @deprecated
	 */
	@Deprecated
	@SuppressWarnings( "unchecked" )
	public static Map< String, Object > getConfig( Map< String, Object > admin ){
		return ( Map< String, Object > ) admin.get( Constants.AGENT_CONFIG_IN_SESSION );
	}
	/**
	 * 是否有附加权限
	 * @param admin
	 * @return
	 * @deprecated
	 */
	@Deprecated
	public static boolean hasConfig( Map< String, Object > admin ){
		
		Object hasConfig =  admin.get( Constants.CONFIG_NAME );
		if( hasConfig == null ){
			return false;
		}
		
		return ( Boolean ) hasConfig;
	}
	
	public static int getAdminLevel( Map< String, Object > admin ){
		Object level = admin.get( "level" );
		
		if( level instanceof Integer ){
			return ( Integer ) level;
		}
		
		if( level instanceof Short ){
			return ( Short ) level;
		}
		
		if( level instanceof Byte ){
			return ( Byte ) level;
		}
		
		return 99;
	}
	
	/**
	 * 获取树的节点
	 * @param id
	 * @param pId
	 * @param name
	 * @param url
	 * @param open
	 * @param checked
	 * @param target
	 * @return
	 */
	public static Map< String, Object > getNodes( Object id, Object pId, Object name, Object url, boolean open, boolean checked, String target ){
		Map< String, Object > node = new HashMap< String, Object >( );
		node.put( "id", id );
		node.put( "pId", pId );
		node.put( "name", name );
		node.put( "open", open );
		node.put( "checked", checked );
		node.put( "url", url );
		
		if( StringUtils.isNotBlank( target )){
			node.put( "target", target );
		}
		
		
		
		
		return node;
	}
}
